package com.swcn.u_pet;

import java.util.List;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;




    /** Called when the activity is first created. */
public class Stepsfront extends Activity{
	    /** Called when the activity is first created. */

		private Steps mainView;
		
		private SensorManager sensorManager;
		
		private AccelerometerListener accelerometerListener;

		private boolean registedAccelSensor,registedMagnesticFieldSensor;
		
	  
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        mainView = new Steps(this);
	      
	        setContentView(mainView);
	        
	        sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
	        accelerometerListener = new AccelerometerListener(mainView);
	        registedAccelSensor = false;
	        registedMagnesticFieldSensor = false;
	    }
	    
	    public AccelerometerListener getAccelerometerListener()
	    {
	    	return accelerometerListener;
	    }
	    
	    protected void onResume(){
	    	
	    	List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
	    
	    	if(sensors.size() > 0)
	    		registedMagnesticFieldSensor = sensorManager.registerListener(accelerometerListener, sensors.get(0), SensorManager.SENSOR_DELAY_GAME);
	    	
	    	
	    	sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
	    	
	    	if(sensors.size() > 0)
	    		registedAccelSensor = sensorManager.registerListener(accelerometerListener, sensors.get(0), SensorManager.SENSOR_DELAY_GAME);
	    	
	    	super.onResume();
	    	
	    }
	    
	    protected void onPause(){
	    if(registedMagnesticFieldSensor || registedAccelSensor){
	    	sensorManager.unregisterListener(accelerometerListener);
	    	registedMagnesticFieldSensor = false;
	    	registedAccelSensor = false;
	    }
	        super.onPause();
	    }
}
//	private Steps steps;
//	
//	private SensorManager sensorManager;
//	
//	private AccelerometerListener accelerometerListener;
//
//	private boolean registedAccelSensor,registedMagnesticFieldSensor;
//	
//  
//    public void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        steps = new Steps(this);
//        
//        setContentView(steps);
//        
//        sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
//        accelerometerListener = new AccelerometerListener(steps);
//        registedAccelSensor = false;
//        registedMagnesticFieldSensor = false;
//    }
//    
//    public AccelerometerListener getAccelerometerListener()
//    {
//    	return accelerometerListener;
//    }
//    
//    protected void onResume(){
//    	
//    	List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
//    
//    	if(sensors.size() > 0)
//    		registedMagnesticFieldSensor = sensorManager.registerListener(accelerometerListener, sensors.get(0), SensorManager.SENSOR_DELAY_GAME);
//    	
//    	
//    	sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
//    	
//    	if(sensors.size() > 0)
//    		registedAccelSensor = sensorManager.registerListener(accelerometerListener, sensors.get(0), SensorManager.SENSOR_DELAY_GAME);
//    	
//    	super.onResume();
//    	
//    }
//    
//    protected void onPause(){
//    if(registedMagnesticFieldSensor || registedAccelSensor){
//    	sensorManager.unregisterListener(accelerometerListener);
//    	registedMagnesticFieldSensor = false;
//    	registedAccelSensor = false;
//    }
//        super.onPause();
//    }
//}